package cn.xz.mxxz.net;

import android.content.Context;

import cn.xz.mxxz.util.ToastUtil;
import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.Request;

/**
 * 返回处理类
 * 
 */
public abstract class OkhttpResponseHandle<T> extends OkhttpAsyncResponseHandler<T> {
    private FormBody.Builder mFormBodyBuilder;//带有key-value表单的请求
    private static String NET_BAD = "网络不给力,请检查网络";

    /**
     * 需要传参数的可以在回调的RequestParams对象中传入字段参数
     *
     * @return RequestParams对象
     */
    public void setFormParams(FormBody.Builder formBodyBuilder) {
        mFormBodyBuilder = formBodyBuilder;
    }

    public FormBody.Builder getFormParams() {
        return mFormBodyBuilder;
    }

    /**
     * 如果需要传表单形式,需要在外面实现该方法
     *
     * @param formBody
     * @return
     */
    public FormBody addFormParams(FormBody formBody) {
        return formBody;
    }

    @Override
    public void networkHandler(Context context) {

    }

    @Override
    public void networkUnAvailable(Context context) {
        ToastUtil.INSTANCE.show(NET_BAD);
    }

    @Override
    public void onToast(String str) {
        ToastUtil.INSTANCE.show(str);
    }

    @Override
    public void onStart(Call call, Request request) {
     /*   Log("url:" + request.url().toString());
        Log.e("header:" + request.headers().toString());*/
    }

    @Override
    public void onSuccessByOtherStatus(T response) {

    }

    @Override
    public boolean isNeedShowStatusInfo() {
        return true;
    }

    @Override
    public void onFailure(Request request, Exception e) {
        e.printStackTrace();
    }

    @Override
    public void onFinish() {

    }
}
